package com.techme.jetpack.navigation


import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import com.example.jetpack_android_online.R
import com.example.jetpack_android_online.databinding.LayoutFragmentTagsBinding

class TagsFragment : BaseFragment() {
    lateinit var tagsBinding: LayoutFragmentTagsBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        tagsBinding = LayoutFragmentTagsBinding.inflate(inflater, container, false)
        return tagsBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // homeFragment -- categoryFragment -- tagsFragment ------ userFragment
        // ------NavOptions
        tagsBinding.navigateToUserFragment.setOnClickListener {
            findNavController().popBackStack(R.id.home_fragment, inclusive = false, saveState = true)

            // 跳转到user_fragment
//            findNavController().navigate(R.id.user_fragment, null,
//                NavOptions.Builder()
//                    .setLaunchSingleTop(true)
//                    .setPopUpTo(destinationId = R.id.home_fragment, inclusive = false, saveState = true)
//                    .build()
//            )
        }

        tagsBinding.getStackTopFragment.setOnClickListener {
            val navController = findNavController()
            val currentDestination = navController.currentDestination
            Log.e("TAG", "CategoryFragment currentFragment: $currentDestination" )


            val allFragments = findNavController()
        }
    }

}